package cn.edu.scnu.semart.user.controller;

import cn.edu.scnu.semart.common.result.Result;
import cn.edu.scnu.semart.common.utils.UserContext;
import cn.edu.scnu.semart.user.service.UserService;
import cn.edu.scnu.semart.vo.user.ChangePwdVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/user/profile")
@Api(tags = "个人中心")
public class UserProfileController {

    @Resource
    private UserService userService;

    @PostMapping("/changePwd")
    @ApiOperation("用户或管理员修改自己的密码")
    public Result changePwd(@Valid @RequestBody ChangePwdVo vo,
                            HttpServletRequest request) {
        Integer currentUserId = UserContext.getUserId(request);
        userService.changePassword(currentUserId, vo);
        return Result.ok(null);
    }
}